package main

import (
	"fmt"
	"log"

	"github.com/FISCO-BCOS/go-sdk/client"
	"github.com/FISCO-BCOS/go-sdk/conf"
	"github.com/ethereum/go-ethereum/common"
)

func main() {
	//1. 读取配置文件
	configs, err := conf.ParseConfigFile("config.toml")
	if err != nil {
		log.Fatalf("ParseConfigFile failed, err: %v", err)
	}

	//2. 连接到节点
	client, err := client.Dial(&configs[0])
	if err != nil {
		log.Fatal(err)
	}
	//3. 创建合约实例
	instance, err := NewHello(common.HexToAddress("0x0be05891a347b194f3b6921451e81ebb34bb7264"), client)
	if err != nil {
		log.Panic("failed to NewHello", err)
	}
	//4. 合约函数调用
	mymsg, err := instance.GetMsg(client.GetCallOpts())
	if err != nil {
		log.Panic("failed to GetMsg", err)
	}
	fmt.Println("msg:", mymsg)
	//5. 修改
	_, _, err = instance.SetMsg(client.GetTransactOpts(), "luxiaojia")
	if err != nil {
		log.Panic("failed to SetMsg", err)
	}
	mymsg, err = instance.GetMsg(client.GetCallOpts())
	if err != nil {
		log.Panic("failed to GetMsg", err)
	}
	fmt.Println("msg:", mymsg)
}
